<?php

namespace app\home\controller;

use app\common\controller\Home;
use think\Db;

class Ranking extends Home
{
    protected $RankingModel = null;
    protected $SubjectModel = null;

    public function __construct()
    {
        parent::__construct();

        $this->RankingModel = model('Ranking.Ranking');
        $this->SubjectModel = model('Subject.Subject');
    }

    public function ranking()
    {
        $list = $this->RankingModel->with(['subject', 'business'])->field(Db::raw('COUNT(distinct(`busid`)) as `count_sum`'))->group('subid')->order('count_sum', 'desc')->select();
        $subject = $this->SubjectModel->with(['category', 'teacher'])->select();

        $number = 1;

        $this->assign([
            'list' => $list,
            'number' => $number,
            'subject' => $subject,
        ]);

        return $this->view->fetch();
    }
}
